<html>
  <body>

  </body>
  <script>
    //1.阴阳(阴|阳)
    //2.五星（阳木|阴木|阳火|阴火|阳土|阴土|阳金|阴金 |阳水|阴水）
    //3.方位（东｜南｜西｜北｜东南｜东北｜西南｜西北）
    //4.冬｜夏
    const taoist = (wuxing, position, season) => {
      if(!wuxing || !position || !season) {
        alert('参数缺失');
        return;
      }
      const wuxingData = {
        '阳木' : [0, '甲', '震'],
        '阴木' : [1, '乙', '巽'],
        '阳火' : [2, '丙', '离'],
        '阴火' : [3, '丁', '离'],
        '阳土' : [4, '戊', '艮'],
        '阴土' : [5, '己', '坤'],
        '阳金' : [6, '庚', '乾'],
        '阴金' : [7, '辛', '兑'],
        '阳水' : [8, '壬', '坎'],
        '阴水' : [9, '癸', '坎'],
      }
      const res = [{
        num: 1,
        fixed: ['子'],
        position: '北',
      }, {
        num: 2,
        fixed: ['申未'],
        position: '西南',
      }, {
        num: 3,
        fixed: ['卯'],
        position: '东',
      }, {
        num: 4,
        fixed: ['巳辰'],
        position: '东南',
      }, {
        num: 5, 
        fixed: [''],
        position: '',
      }, {
        num: 6, 
        fixed: ['戌亥'],
        position: '西北',
      }, {
        num: 7, 
        fixed: ['酉'],
        position: '西',
      }, {
        num: 8, 
        fixed: ['寅丑'],
        position: '东北',
      }, {
        num: 9, 
        fixed: ['午'],
        position: '南',
      }, {
        num: 10,
        fixed: [],
      }];
      const clockwise = [1, 8, 3, 4, 9, 2, 7, 6];
      let resIndex = 0;
      const clockwiseSort = (num) => {
        const idx = clockwise.indexOf(num);
        const arr = [...clockwise.slice(idx), ...clockwise.slice(0, idx)];
        return arr;
      }
      const clockwiseWord = ['休', '生', '伤', '杜', '景', '死', '惊'];
      res.forEach((item, index) => {
        if (item.position === position) {
          resIndex = index;
          item.fixed.push(wuxingData[wuxing][1] + '开');
          item.fixed.push(wuxingData[wuxing][2]);
          const revertIndex = 10 - item.num;
          res[revertIndex - 1].fixed.push(wuxingData[wuxing][2]);

          const clockwiseArr = clockwiseSort(item.num);
          clockwiseWord.forEach((txt, idx) => {
            const point = clockwiseArr[idx + 1];
            res[point - 1].fixed.push(txt);
          })
        }
      })
      
      // 夏至减法，冬至加法
       wuxingIndex = wuxingData[wuxing][0];
       const wuxingArr = Object.values(wuxingData);
      if (season === '夏'){
        for(let i = 1, resIdx = resIndex - 1, wuxingIdx = wuxingIndex + 1; i < 10; i ++, wuxingIdx ++, resIdx --) {
          if (wuxingIdx === 10) wuxingIdx = 0;
          if (resIdx === -1) resIdx = 8;
          if (i === 9) {
            res[9].fixed.push(wuxingArr[wuxingIdx][1])
          } else {
            res[resIdx].fixed.push(wuxingArr[wuxingIdx][1])
          }
        }
      } else if (season === '冬') {
        for(let i = 1, resIdx = resIndex + 1, wuxingIdx = wuxingIndex + 1; i < 10; i ++, wuxingIdx ++, resIdx ++) {
          if (wuxingIdx === 10) wuxingIdx = 0;
          if (resIdx === 9) resIdx = 0;
          if (i === 9) {
            res[9].fixed.push(wuxingArr[wuxingIdx][1])
          } else {
            res[resIdx].fixed.push(wuxingArr[wuxingIdx][1])
          }
        }
      }
      
      // 根据阴阳隔三个填写，阳减法，阴加法
      const yang = ['', '', '', '丑', '亥', '酉', '未', '巳', '卯'];
      const yin = ['', '', '', '子', '戌', '申', '午', '辰', '寅'];
      const yinyang = wuxing.slice(0, 1);
      if (season === '夏') {
        for (let i = 1, count = 3, idx = resIndex; i < 10; i++, count--, idx--) {
          if (idx === -1) idx = 8;
          if (count <= 0) {
            if (yinyang === '阳') {
              res[idx].fixed.push(yang[i - 1]);
            } else if (yinyang === '阴') {
              res[idx].fixed.push(yin[i - 1]);
            }
          }
        }
      } else if (season === '冬') {
        for (let i = 1, count = 3, idx = resIndex; i < 10; i++, count--, idx++) {
          if (idx === 9) idx = 0;
          if (count <= 0) {
            if (yinyang === '阳') {
              res[idx].fixed.push(yang[i - 1]);
            } else if (yinyang === '阴') {
              res[idx].fixed.push(yin[i - 1]);
            }
          }
        }
      }
      return res
    }
    const resArr = taoist('阳木', '北', '夏');
    console.log(resArr)
  </script>
</html>